package com.ming.reggie.mapper;

import com.ming.reggie.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author ming
 */
public interface ShoppingCartMapper {
    //查询购物车中当前菜品或套餐的购物车数据
    ShoppingCart findByShoppingCart(ShoppingCart shoppingCart);

    //更新指定购物车菜品数据数量
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    Integer updateNumber(@Param("id") Long id,@Param("number") Integer number);

    //插入新的一条菜品数据
    @Insert("insert into shopping_cart values (null,#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    Integer save(ShoppingCart shoppingCart);

    @Select("select * from shopping_cart where user_id = #{UserId} ")
    List<ShoppingCart> findAllByUserId(Long UserId);

    //删除指定用户购物车数据
    @Delete("delete from shopping_cart where user_id = #{userId}")
    Integer deleteByUserId(Long userId);
}
